//
//  EMRootViewController.m
//  ElectronicMall
//
//  Created by 史伟文 on 14/12/21.
//  Copyright (c) 2014年 cczu. All rights reserved.
//

#import "EMRootViewController.h"
#import "EMFirstPageViewController.h"
#import "EMCategoryViewController.h"
#import "EMNewGoodsViewController.h"
#import "EMShoppingCartViewController.h"
#import "EMMemberCenterViewController.h"


@interface EMRootViewController ()

@end

@implementation EMRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self loadEachChildViewController];
}

- (void)loadEachChildViewController
{
    [self initChildViewCotroller:[[EMFirstPageViewController alloc] init] title:@"首页" image:[UIImage imageNamed:@"icon_首页"] selectedImage:[UIImage imageNamed:@"icon_首页_选中"]];
    
    [self initChildViewCotroller:[[EMCategoryViewController alloc] init] title:@"分类" image:[UIImage imageNamed:@"icon_分类"] selectedImage:[UIImage imageNamed:@"icon_分类_选中"]];
    
    [self initChildViewCotroller:[[EMNewGoodsViewController alloc] init] title:@"新品" image:[UIImage imageNamed:@"icon_新品"] selectedImage:[UIImage imageNamed:@"icon_新品_选中"]];
    
    [self initChildViewCotroller:[[EMShoppingCartViewController alloc] init] title:@"购物车" image:[UIImage imageNamed:@"icon_购物车"] selectedImage:[UIImage imageNamed:@"icon_购物车_选中"]];
    
    [self initChildViewCotroller:[[EMMemberCenterViewController alloc] init] title:@"个人中心" image:[UIImage imageNamed:@"icon_个人中心"] selectedImage:[UIImage imageNamed:@"icon_个人中心_选中"]];
}
- (void)initChildViewCotroller:(UIViewController *)controller title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    // 109,176,81
    NSDictionary *normalAttributeDict = @{
                                          NSForegroundColorAttributeName:[UIColor grayColor],
                                          NSFontAttributeName:[UIFont fontWithName:HEITIMEDIUM size:12]
                                          };
    NSDictionary *highlightAttributeDict = @{
                                             NSForegroundColorAttributeName:RGB(109, 176, 81),
                                             NSFontAttributeName:[UIFont fontWithName:HEITIMEDIUM size:12]
                                             };
    [[UITabBarItem appearance] setTitleTextAttributes:normalAttributeDict forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:highlightAttributeDict forState:UIControlStateSelected];
    
    controller.tabBarItem.title = title;
    controller.tabBarItem.image = image;
    controller.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
    [self addChildViewController:navi];
}

@end
